import 'package:get/get.dart';

class EnvConfig {
  final String baseUrl;
  final bool debugEnable;

  EnvConfig({required this.baseUrl, this.debugEnable = true});

  String get wssUrl => 'wss://${baseUrl.replaceAll('https://', '')}/family-guard/ws/app';

  String get userAgreementUrl => "$baseUrl/provisions/zqsh/user-agreement.html";

  String get privacyPolicyUrl => "$baseUrl/provisions/zqsh/privacy-policy-2.html";
}

class Env {
  // 获取到当前环境
  static const _appEnv = String.fromEnvironment(EnvName.envKey, defaultValue: 'test');
  static const _enableDebug = bool.fromEnvironment(EnvName.envEnableDebugKey, defaultValue: false);

  // 开发环境
  static final EnvConfig _debugConfig = EnvConfig(
    baseUrl: 'https://zqsh.frp.chinaxdr.com',
  );

  // 发布环境
  static final EnvConfig _releaseConfig = EnvConfig(
    baseUrl: 'https://zqsh.xdr-tec.com',
    debugEnable: false,
  );

  // 测试环境
  static final EnvConfig _testConfig = EnvConfig(baseUrl: 'https://zqsh-test.xdr-tec.com:8043');

  static EnvConfig get envConfig => _getEnvConfig();

  static EnvType get appEnv => EnvType.values.firstWhereOrNull((e) => e.name == _appEnv) ?? EnvType.debug;

// 根据不同环境返回对应的环境配置
  static EnvConfig _getEnvConfig() {
    switch (appEnv) {
      case EnvType.debug:
        return _debugConfig;
      case EnvType.release:
        return _releaseConfig;
      case EnvType.test:
        return _testConfig;
      default:
        return _debugConfig;
    }
  }
}

enum EnvType {
  debug,
  release,
  test,
}

// 声明的环境
abstract class EnvName {
  // 环境key
  static const String envKey = "flavor";
  static const String envEnableDebugKey = "enableDebug";
}
